package com.alan.camunda.boot.test;

import cn.hutool.core.io.FileUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class KillMongoOperation {

    public static void main(String[] args) {

        List<String> lines = FileUtil.readLines("C:\\Users\\Alex\\Desktop\\activeOp.txt", "utf-8");
        List<String> opidList = new ArrayList<>();

        for (String line : lines) {
            if (line.contains("\"opid\" :")) {
                System.out.println(line);
                opidList.add(extractOpid(line));
            }
        }

        for (String opId : opidList) {

            System.out.println("db.killOp(\"" + opId + "\");");

        }



    }

    public static String extractOpid(String input) {
        // 正则表达式：匹配任意数量的空格后，再匹配 "opid" : " 任意字符 "
        Pattern pattern = Pattern.compile("\\s*\"opid\"\\s*:\\s*\"([^\"]+)\"");
        Matcher matcher = pattern.matcher(input);

        if (matcher.find()) {
            return matcher.group(1);
        } else {
            return null; // 如果没有匹配到内容，返回null
        }
    }

}
